
/*
 * @项目名称: 模板开发
 * @FilePath: /meek/src/utils/math.js
 * @Author: 1106408264@qq.com
 * @Date: 2017-06-05T15:23:51+08:00
 * @LastEditors: 
 * @LastEditTime: 2021-01-29T16:53:45+08:00
 * Copyright (c) 2018-2022
 */

/**
 * Created by zhangyong on 2017/6/5.
 */



export function clamp (value, min, max) {
  return Math.min(Math.max(value, min), max)
}


export function lerp (a, b, x) {
  return a + x * (b - a)
}

/**
 * Returns the modulo of a / b, depending on the sign of b.
 *
 * @param {number} a Dividend.
 * @param {number} b Divisor.
 * @return {number} Modulo.
 */
export function modulo(a, b) {
  const r = a % b;
  return r * b < 0 ? r + b : r;
}

/**
 * Converts degrees to radians.
 *
 * @param {number} angleInDegrees Angle in degrees.
 * @return {number} Angle in radians.
 */
export function toRadians(angleInDegrees) {
  return angleInDegrees * Math.PI / 180;
}

/**
 * Converts radians to to degrees.
 *
 * @param {number} angleInRadians Angle in radians.
 * @return {number} Angle in degrees.
 */
export function toDegrees(angleInRadians) {
  return angleInRadians * 180 / Math.PI;
}


export default {
  clamp,
  lerp,
  modulo,
  toRadians,
  toDegrees
}
